<?php
/**
* @package YARBB
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/

	defined( '_JEXEC' ) or die( 'Restricted Access' );
	global $ybbConfig;
	$dispclr = $this->theme;
?>
<script language="javascript" type="text/javascript">

_YBB_JS_EDITOR_PATH = '<?php echo JURI::root(); ?>components/com_yarbb/assets/ybbeditor';

function setgood() {
	// TODO: Put setGood back
	return true;
}

function submitbutton(pressbutton)
{
	var form = document.postForm;
	if (pressbutton == "cancelPost") {
		form.submit();
		return;
	}
	if (pressbutton == "previewpost") {
        form.task.value="previewpost";
		form.submit();
		return;
	}

    // do field validation
	var sub = form.post_subject.value;
	if (sub == '') {
		alert ( "<?php echo $this->labels['invalidsub']; ?>");
		return;
	}

	var text='';
	<?php
		if( $ybbConfig->ybbeditor == 'yarbb' )
		{
			echo 'text= document.getElementById("post_text").value;';

		} else {
			 echo 'text=' . $this->editor->getContent( 'post_text' );
			 echo $this->editor->save( 'post_text' );
		}
	?>

	if (text == '') {
		alert ( "<?php echo $this->labels['invalidtext']; ?>");
		return;
	}

	var guest = <?php echo $this->guest; ?>;
	var username = form.username.value;
	if( guest == 1 && username == '' ) {
		alert ( "<?php echo $this->labels['invalidusername']; ?>");
		return;
	}


	form.task.value="savePost";
	form.submit();
}

function viewPost()
{
	el = document.getElementById('dvPreview');
	if( el.style.display == "block" ) {
		el.style.display="none";
	} else {
		el.style.display="block";
		var text = <?php if( $ybbConfig->ybbeditor  == 'yarbb' ) {
							echo 'text= document.getElementById("post_text").value;';
						}	else {
							echo $this->editor->getContent( 'post_text' );
						}
					?>
		var el = document.getElementById('pvcontent');
		el.innerHTML = text;
	}
}



function uploadAttachment()
{
    <?php echo $this->editor->save( 'post_text' ); ?>
            
	var form = document.postForm;
	form.task.value="uploadAttachment";
	form.submit();

}

function deleteAttachment( aid )
{
    <?php echo $this->editor->save( 'post_text' ); ?>
            
	var form = document.postForm;
	form.attachid.value = aid;
	form.task.value="deleteAttachment";
	form.submit();
}

</script>
<?php
	if( $ybbConfig->ybbeditor  == 'yarbb' ) {
		echo '<script src="' . $this->path . 'components/com_yarbb/assets/ybbeditor/ed.js" language="javascript" type="text/javascript"></script>';
	}

 ?>

<form action="<?php echo $this->action; ?>" method="post" name="postForm" id="postForm"  enctype="multipart/form-data" onSubmit="setgood();">
  <div class="ybbmaindiv">
    <table class="ybbnormaltable" cellpadding="0" cellspacing="0">
      <tr>
        <td class="ybbtopleft"></td>
        <td class="ybbtopmiddle">&nbsp;<?php echo $this->page_title; ?></td>
        <td class="ybbtopright"></td>
      <tr>
      <tr>
        <td class="ybbleftbody"></td>
        <td class="ybbtpkdetail"><table class="ybbnormaltable" cellpadding="0" cellspacing="0">
            <tr>
              <td class="ybbeditsubjlabel">&nbsp;</td>
              <td class="ybbeditsubj">&nbsp;</td>
            </tr>
            <?php if( $this->guest > 0 ) { ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['username']; ?></b></td>
              <td class="ybbeditsubj"><input class="ybbeditsubj" type="text" name="username" id="username" size="40" maxlength="100" value="<?php echo $this->username; ?>" />
              </td>
            </tr>
            <?php } else {
						echo '<tr><td></td><td><input type="hidden" id="username" name="username" value="' . $this->username. '" /></td></tr>';
					} ?>
            <?php // if( $this->mode <> 'reply' && $this->mode <> 'quote' ) {
                          // Commented out for promoting existing thread to Announcement / Viceversa
							   if( $this->modeactions > 0) {
								   //if( $this->id == 0 || $this->topictype > 0 ) { ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['topictype']; ?>:</b></td>
              <td class="ybbeditsubj"><?php echo $this->topiccombo; ?></td>
            </tr>
            <?php          // }
                                }
                            //}
                            if( ($this->mode == 'post') || ($this->mode == 'edit' && $this->id == $this->startPost) ) { ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['topicicon']; ?>:</b></td>
              <td class="ybbeditsubj">&nbsp;
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "0" <?php echo $this->topic_emoticon == 0 ? 'checked="checked"':''; ?> />
                <?php echo JText::_('NONE'); ?>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "1" <?php echo $this->topic_emoticon == 1 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/1.gif" alt= "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "2" <?php echo $this->topic_emoticon == 2 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/2.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "3" <?php echo $this->topic_emoticon == 3 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/3.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "4" <?php echo $this->topic_emoticon == 4 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/4.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "5" <?php echo $this->topic_emoticon == 5 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/5.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "6" <?php echo $this->topic_emoticon == 6 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/6.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "7" <?php echo $this->topic_emoticon == 7 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/7.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "8" <?php echo $this->topic_emoticon == 8 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/8.gif" alt = "" border = "0"/>
                <input type = "radio" id="topic_emoticon" name = "topic_emoticon" value = "9" <?php echo $this->topic_emoticon == 9 ? 'checked="checked"':''; ?> />
                <img src = "<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/topic_icon/9.gif" alt = "" border = "0"/> </td>
            </tr>
            <?php   }
						  else {
							echo '<tr><td></td><td><input type="hidden" id="topic_emoticon" name="topic_emoticon" value="' . $this->topic_emoticon . '" /></td></tr>';
						  } ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['subject']; ?>:</b></td>
              <td class="ybbeditsubj"><input class="ybbeditsubj" type="text" name="post_subject" id="post_subject" size="<?php echo $ybbConfig->subjwidth; ?>" maxlength="100" value="<?php echo $this->post_subject; ?>" /></td>
            </tr>
            <tr>
              <td colspan="2" class="ybbedittext"><?php
								if( $ybbConfig->ybbeditor  == 'yarbb' ) {
									echo '<script type="text/javascript"> edToolbar("post_text", 1); </script>';
									echo '<div class="smyle_ybb"><script type="text/javascript"> edSmyleBar("post_text", 1); </script></div>';
									echo '<div class="texarea_ybb"><textarea id="post_text" name = "post_text" cols="'. $ybbConfig->editorwidth . '"  width="" rows="'. $ybbConfig->editorheight . '" height>'. $this->post_text . '</textarea></div>';
								} else {
									echo $this->editor->display('post_text', $this->post_text, $ybbConfig->editorwidth , $ybbConfig->editorheight, '70', '15', false);
								}
							?>
              </td>
            </tr>
            <tr>
              <td class="ybbeditsubjlabel">&nbsp;</td>
              <td class="ybbeditsubj">&nbsp;</td>
            </tr>
            <?php if( $this->guest < 1 && $ybbConfig->emailsub > 0 && $this->mode <> 'edit') { ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['subscribe']; ?>:</b></td>
              <td class="ybbeditsubj"><?php echo $this->autosub; ?></td>
            </tr>
            <?php } else { ?>
            <tr>
              <td></td>
              <td><input type="hidden" name="autosub" id="autosub" value="0" /></td>
            </tr>
            <?php } ?>
            <?php if( $this->uploadPermission ) {
					foreach($this->attachments as $key => $value) { ?>
            <tr>
              <td class="ybbeditsubj" colspan="2"><img src="<?php echo YARBB_ASSETS_URL_THEME.'/'.$dispclr; ?>/img/attach.png"/> <?php echo $value[1] . ' [' . (int) ($value[3]/1024) . ' KB]'; ?>; <a href="#" onclick="deleteAttachment('<?php echo $value[0]; ?>'); return false;">[<?php echo JText::_('DELETE'); ?>]</a>::<?php echo $value[5]; ?> </td>
            </tr>
            <?php } ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['attachments']; ?>:</b></td>
              <td class="ybbeditsubj"><input size="37" type="file" id="file-upload" name="Filedata" /></td>
            </tr>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['attachmentcomment'] ?>:</b></td>
              <td class="ybbeditsubj"><div class="ybbuploadbut">
                  <input class="attachtext" type="text" maxlength="250" id="attachmentcomment" name="attachmentcomment" />
                </div>
                <div class="ybbuploadbut"> <a rel="nofollow" class="ovalbutton" href="#" onclick="uploadAttachment(); return false;"> <span><?php echo  JText::_('BUTTON_UPLOAD'); ?></span> </a> </div>
              <td>
            </tr>
            <?php } ?>
            <?php if( $this->mode == 'edit' ) { ?>
            <tr>
              <td class="ybbeditsubjlabel"><b><?php echo $this->labels['editreason']; ?>:</b></td>
              <td class="ybbeditsubj"><input class="ybbeditsubj" type="text" name="modified_reason" id="modified_reason" size="<?php echo $ybbConfig->subjwidth; ?>" maxlength="255" value="<?php echo $this->modified_reason; ?>" /></td>
            </tr>
            <tr>
              <td colspan="2" class="ybbcolspacer"></td>
            </tr>
            <?php } else {
						echo '<tr><td></td><td><input type="hidden" id="modified_reason" name="modified_reason" value="" /></td></tr>';
				} ?>
            <tr>
              <td colspan="2"><table class="ybbnormaltable" cellpadding="0" cellspacing="0">
                  <tr>
                    <?php if( $this->cap_path <> '' ) { ?>
                    <td class="ybbeditsubjlabel"><b><?php echo $this->labels['captcha']; ?>:</b></td>
                    <td class="ybbeditcap"><img id="imgcap" name="imgcap" src="<?php echo $this->cap_path;?>"  /></td>
                    <td class="ybbeditcaptext"><input class="ybbeditcapinput" type="text" id="captcha" name="captcha" maxlength="5" autocomplete="off" /></td>
                    <?php }
										else {
                                        	echo '<td><input type="hidden" id="captcha" name="captcha"/><td>';
										}
									?>
                    <td><div class="buttonarea">
                        <?php if( $ybbConfig->ybbeditor == 'joomla') { ?>
                        <a rel="nofollow" class="ovalbutton" href="#" onclick="viewPost(); return false;"> <span><?php echo $this->labels['preview']; ?></span> </a>
                        <?php } else { ?>
                        <a rel="nofollow" class="ovalbutton" href="#" onclick="submitbutton('previewpost'); return false;"> <span><?php echo $this->labels['preview']; ?></span> </a>
                        <?php } ?>
                        <a rel="nofollow" class="ovalbutton" href="#" onclick="submitbutton('savePost'); return false;"> <span><?php echo $this->labels['save']; ?></span> </a> <a rel="nofollow" class="ovalbutton" href="#" onclick="submitbutton('cancelPost'); return false;"> <span><?php echo $this->labels['cancel']; ?></span> </a> </div></td>
                  </tr>
                </table></td>
            </tr>
            <tr>
              <td colspan="2" class="ybbcolspacer"></td>
            </tr>
          </table></td>
        <td class="ybbrightbody"></td>
      </tr>
      <tr class="ybbtablefooter">
        <td class="ybbbotleft"></td>
        <td class="ybbbotmiddle"></td>
        <td class="ybbbotright"></td>
      </tr>
      <tr>
        <td colspan="3" class="ybbcolspacer"></td>
      </tr>
    </table>
  </div>
  <input type="hidden" name="option" value="com_yarbb" />
  <input type="hidden" id="task" name="task" value="cancelPost" />
  <input type="hidden" name="<?php echo JUtility::getToken(); ?>" value="1" />
  <input type="hidden" name="id" value="<?php if ( ((int)$this->id) > 0 ){ echo $this->id; } ?>" />
  <input type="hidden" name="forum_id" value="<?php echo (int)$this->forum_id; ?>" />
  <input type="hidden" name="topic_id" value="<?php echo (int)$this->topic_id; ?>" />
  <input type="hidden" name="mode" value="<?php echo $this->mode; ?>" />
  <input type="hidden" name="attachid" value="" />
</form>
<div id="dvPreview" class="ybbeditpreview">
  <table class="ybbnormaltable" cellpadding="0" cellspacing="0">
    <tr>
      <td class="ybbtopleft"></td>
      <td class="ybbtopmiddle">&nbsp;<?php echo $this->page_title; ?></td>
      <td class="ybbtopright"></td>
    <tr>
    <tr>
      <td class="ybbleftbody"></td>
      <td><table class="ybbnormaltable" cellpadding="0" cellspacing="6">
          <tr>
            <td class="ybbuserinfo"><table  class="ybbnormaltable" cellpadding="5" cellspacing="0">
                <tr>
                  <td class="ybbpstusername"><b><?php echo  JText::_('LAST_EDIT_BY'); ?></b></td>
                </tr>
                <tr>
                  <td class="ybbpostcenter"><img src="components/com_yarbb/assets/avatar/avatar1.png" class="ybbpostavatar" /></td>
                </tr>
                <tr>
                  <td></td>
                </tr>
              </table></td>
            <td id="pvcontent" class="ybbposttextcol"><?php
                                if( $ybbConfig->ybbeditor == 'yarbb' ) {
                                	require_once ('components/com_yarbb/assets/ybbeditor/ybbeditor.php');
                                    $bbcode = new ybbEditor();
                                    echo $bbcode->parseContent($this->post_text);
                                }
                            ?>
            </td>
          </tr>
        </table></td>
      <td class="ybbrightbody"></td>
    </tr>
    <tr class="ybbtablefooter">
      <td class="ybbbotleft"></td>
      <td class="ybbbotmiddle"></td>
      <td class="ybbbotright"></td>
    </tr>
    <tr>
      <td colspan="3" class="ybbcolspacer"></td>
    </tr>
  </table>
</div>
<script>
<?php
    if( $this->preview == 'previewpost') {
        echo 'elem = document.getElementById("dvPreview");';
        echo 'elem.style.display="block";';
    }
?>
</script>
<br/>
<br clear="left"/>
<?php echo YARBB_COPYRIGHT; ?> <br/>
<br clear="left"/>
